﻿namespace Hotel.Web.Helpers
{
    using System;

    using ResourcesModule = Hotel.Module.Resources;
    using ManagementModule = Hotel.Module.Management;
    using InfrastructureModule = Hotel.Module.Infrastructure;


    public class ServiceLocator : IServiceProvider
    {
        #region Explicit logic

        public static ServiceLocator Instance
        {
            get
            {
                lock (_mutex)
                {
                    if (m_Instance == null)
                        m_Instance = new ServiceLocator();
                }
                return m_Instance;
            }
        }

        #endregion

        #region IServiceProvider Members

        public object GetService(Type serviceType)
        {
            if (serviceType == typeof(ResourcesModule.IResourseManagment))
            {
                return new ResourcesModule.HotelResourcesController(Instance);
            }

            if (serviceType == typeof(ManagementModule.IManagement))
            {
                return new ManagementModule.ManagementController(Instance);
            }

            return null;
        }

        #endregion

        #region Private fields

        private static readonly object _mutex = new object();

        private static ServiceLocator m_Instance = null;

        #endregion
    }
}